package team.wuyou.util.annotation.log.service;

import org.springframework.stereotype.Service;
import team.wuyou.bean.Result;
import team.wuyou.util.annotation.log.bean.ExceptionLog;
import team.wuyou.util.jdbc.CommonJDBCUtil;

import java.sql.SQLException;

@Service
public class ExceptionLogService {
    public Result insert(ExceptionLog excepLog) throws SQLException {

        int insert = ExceptionLogService.insertExceptionLog(excepLog);
        if (insert>0){
            System.out.println("insert ExceptionLog success");

        }else {

            System.out.println("insert OperationLog fail");
        }
        return null;
    }
    public static int insertExceptionLog(ExceptionLog exceptionLog) throws SQLException {
        // 构造插入 SQL 语句
        String sql = "INSERT INTO ExceptionLog " +
                "(excId, excRequParam, operMethod, excName, excMessage, " +
                "operUserName, operUri, operIp, operVer, operCreateTime) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        // 提取 ExceptionLog 对象的属性值到数组
        Object[] params = {
                exceptionLog.getExcId(),
                exceptionLog.getExcRequParam(),
                exceptionLog.getOperMethod(),
                exceptionLog.getExcName(),
                exceptionLog.getExcMessage(),
                exceptionLog.getOperUserName(),
                exceptionLog.getOperUri(),
                exceptionLog.getOperIp(),
                exceptionLog.getOperVer(),
                exceptionLog.getOperCreateTime()
        };

        // 调用 executeUpdate 方法
        return CommonJDBCUtil.executeUpdate(sql, params);
    }

}


